package com.huawei.appmarket.support.launcher;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.launcher.api.AbsLaunchInterceptor;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import o.Logger;
import o.ContentManager;

public class NoLaunchInterceptor extends AbsLaunchInterceptor {
    public boolean isInterceptor(@NonNull String str) {
        try {
            PackageManager packageManager = ContentManager.getInstant().getContext().getPackageManager();
            if (packageManager == null) {
                return false;
            }
            PackageInfo packageInfo = packageManager.getPackageInfo(str, 129);
            if (packageInfo == null || packageInfo.activities == null) {
                return false;
            }
            for (ActivityInfo activityInfo : packageInfo.activities) {
                if (activityInfo.metaData != null) {
                    String str2 = null;
                    if (activityInfo.metaData.containsKey("APPGALLERY_LAUNCHER")) {
                        str2 = activityInfo.metaData.get("APPGALLERY_LAUNCHER").toString();
                    }
                    if (str2 != null && ("1".equals(str2) || "2".equals(str2))) {
                        Logger.ˎ("AppLauncher", "Packagename is : " + str + "Launch type is : " + str2);
                        return true;
                    }
                }
            }
            return false;
        } catch (NameNotFoundException e) {
            Logger.ˎ("AppLauncher", "Cannot find packageName: " + str);
            return false;
        } catch (Exception e2) {
            Logger.ˎ("AppLauncher", "Cannot get required parameter: " + e2.toString());
            return false;
        }
    }

    public Intent getIntentByPackage(Context context, String str) {
        Intent intent = new Intent();
        if (!(context instanceof Activity)) {
            intent.addFlags(268435456);
        }
        return intent;
    }

    public boolean launchByPackage(@NonNull Context context, Intent intent, @NonNull String str, String str2) {
        try {
            for (ActivityInfo activityInfo : context.getPackageManager().getPackageInfo(str, 129).activities) {
                if (activityInfo.metaData != null && activityInfo.metaData.containsKey("APPGALLERY_LAUNCHER")) {
                    intent.setComponent(new ComponentName(str, activityInfo.name));
                    String obj = activityInfo.metaData.get("APPGALLERY_LAUNCHER").toString();
                    if ("1".equals(obj)) {
                        context.startActivity(intent);
                        return true;
                    } else if ("2".equals(obj)) {
                        intent.addFlags(WXMediaMessage.THUMB_LENGTH_LIMIT);
                        context.startActivity(intent);
                        if (!(context instanceof Activity)) {
                            return true;
                        }
                        ((Activity) context).overridePendingTransition(0, 0);
                        Logger.ˎ("AppLauncher", "Launch without animation.");
                        return true;
                    }
                }
            }
        } catch (NameNotFoundException e) {
            Logger.ˎ("AppLauncher", "Cannot find packageName: " + str);
        } catch (Exception e2) {
            Logger.ˎ("AppLauncher", "Cannot get required parameter: " + e2.toString());
        }
        return false;
    }
}
